package com.hibase.core.bireport.util;

import com.fr.cert.token.JwtBuilder;
import com.fr.cert.token.SignatureAlgorithm;
import com.hibase.core.bireport.config.fr.DefaultJwtBuilder;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
 * @author chenfeng
 * @version 1.0
 * @date 2021/11/18 15:15
 * @des https://gitee.com/cheershi
 */
@UtilityClass
@Slf4j
public class BiUtil {


    public String createJwt(String issuer, String id, String subject, long validTime, String key) {
        //用于生成数字签名，即参数fine_digital_signature的值
        SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
        Date currentTime = new Date();
        Date expirationTime = new Date(currentTime.getTime() + validTime);
        JwtBuilder builder = new DefaultJwtBuilder()
                .setIssuer(issuer)
                .setSubject(subject)
                .setIssuedAt(currentTime)
                .setExpiration(expirationTime)
                .setId(id)
                .signWith(signatureAlgorithm, key);
        return builder.compact();
    }

    public static void main(String[] args) {
        String code = createJwt("", "", "report/wms4.0_test/WmsWarehouseBinCodeCPT.cpt", 180000, "hichain");
        log.info(code);
    }
}
